package com.csgc.camera.widget.mask

import android.content.Context
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.csgc.camera.constants.MaskConfig
import com.csgc.camera.storage.MaskPreference
import com.cysd.spsyxj.R


class MaskWuYe:MaskBase {

    private var xunJianType: TextView? = null
    private var xunJianPerson: TextView? = null
    private var problemRemark: TextView? = null

    private var servicePerson:TextView? = null
    private var serviceCompany:TextView? = null
    private var serviceContent:TextView? = null

    constructor(context: Context?, id:Int) : super(context,null){

        if(id == 0){
            dateStyle = "yyyy-MM-dd EEEE HH:mm"
            customTextColor = ContextCompat.getColor(context!!,R.color.title_color)
            LayoutInflater.from(context).inflate(R.layout.item_mask_wu_ye_1, this, true)
        }else if(id == 1){
            dateStyle = "yyyy-MM-dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_wu_ye_2, this, true)
        }else if(id == 2){
            dateStyle = "yyyy-MM-dd"
            LayoutInflater.from(context).inflate(R.layout.item_mask_wu_ye_3, this, true)
        }else if(id == 3){
            dateStyle = "yyyy-MM-dd EEEE HH:mm"
            LayoutInflater.from(context).inflate(R.layout.item_mask_wu_ye_4, this, true)
        }else if(id == 4){
            dateStyle = "yyyy-MM-dd"
            LayoutInflater.from(context).inflate(R.layout.item_mask_wu_ye_5, this, true)
        }

        if(MaskConfig.maskDateStyle.isNotEmpty()){
            dateStyle = MaskConfig.maskDateStyle
        }
        initView(id)

    }

    private fun initView(typeId:Int){

        date = findViewById(R.id.tv_wu_ye_date)
        time = findViewById(R.id.tv_wu_ye_time)
        location = findViewById(R.id.tv_wu_ye_location)
        customMaskContainer = findViewById(R.id.layout_custom_mask_container)

        location?.text = MaskConfig.maskLocation

        xunJianType = findViewById(R.id.tv_wu_ye_type)
        xunJianPerson = findViewById(R.id.tv_wu_ye_people)
        problemRemark = findViewById(R.id.tv_wu_ye_remark)

        servicePerson = findViewById(R.id.tv_wu_ye_service_people)
        serviceCompany = findViewById(R.id.tv_wu_ye_service_company)
        serviceContent = findViewById(R.id.tv_wu_ye_service)


        changeDateTime()
        MaskConfig.customMaskInfo.forEach {
            val text = TextView(context)
            text.setTextColor(customTextColor)
            text.setTextSize(TypedValue.COMPLEX_UNIT_SP,14f)
            text.text = "${it.title}:${it.content}"
            text.visibility = if (it.isOpen) View.VISIBLE else View.GONE

            customMaskContainer?.addView(text)
        }

        val maskType = MaskPreference.instance.getMaskType()

        MaskConfig.maskMap[maskType]?.forEach {
            if (it.title == "巡检类型"){
                xunJianType?.text = it.content
            }else if (it.title == "巡检人"){
                xunJianPerson?.text = it.content
            }else if (it.title == "问题备注"){
                problemRemark?.text = it.content
            }else if (it.title == "维修人"){
                servicePerson?.text = it.content
            }else if (it.title == "物业单位"){
                serviceCompany?.text = it.content
            }else if (it.title == "维修内容"){
                serviceContent?.text = it.content
            }
        }



    }

    override fun updateItemContent(title: String, content: String) {
        super.updateItemContent(title, content)
        if (title == "巡检类型"){
            xunJianType?.text = content
        }else if (title == "巡检人"){
            xunJianPerson?.text = content
        }else if (title == "问题备注"){
            problemRemark?.text = content
        }else if (title == "维修人"){
            servicePerson?.text = content
        }else if (title == "物业单位"){
            serviceCompany?.text = content
        }else if (title == "维修内容"){
            serviceContent?.text = content
        }

    }

}